package com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjld;

import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjld.vo.DataQueryQjldPageReqVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjld.vo.DataQueryQjldRespVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataqueryqjld.vo.DataQueryQjldSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.queryinfo.framework.common.pojo.PageParam;
import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.common.pojo.CommonResult;
import com.sugar.queryinfo.framework.common.util.object.BeanUtils;
import static com.sugar.queryinfo.framework.common.pojo.CommonResult.success;

import com.sugar.queryinfo.framework.excel.core.util.ExcelUtils;

import com.sugar.queryinfo.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.queryinfo.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.queryinfo.module.business.dal.dataobject.dataqueryqjld.DataQueryQjldDO;
import com.sugar.queryinfo.module.business.service.dataqueryqjld.DataQueryQjldService;

@Tag(name = "管理后台 - 数据查询-全景雷达")
@RestController
@RequestMapping("/business/data-query-qjld")
@Validated
public class DataQueryQjldController {

    @Resource
    private DataQueryQjldService dataQueryQjldService;

    @PostMapping("/create")
    @Operation(summary = "创建数据查询-全景雷达")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjld:create')")
    public CommonResult<Long> createDataQueryQjld(@Valid @RequestBody DataQueryQjldSaveReqVO createReqVO) {
        return success(dataQueryQjldService.createDataQueryQjld(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新数据查询-全景雷达")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjld:update')")
    public CommonResult<Boolean> updateDataQueryQjld(@Valid @RequestBody DataQueryQjldSaveReqVO updateReqVO) {
        dataQueryQjldService.updateDataQueryQjld(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除数据查询-全景雷达")
    @Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjld:delete')")
    public CommonResult<Boolean> deleteDataQueryQjld(@RequestParam("id") Long id) {
        dataQueryQjldService.deleteDataQueryQjld(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除数据查询-全景雷达")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjld:delete')")
    public CommonResult<Boolean> deleteDataQueryQjldList(@RequestParam("ids") List<Long> ids) {
        dataQueryQjldService.deleteDataQueryQjldListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据查询-全景雷达")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjld:query')")
    public CommonResult<DataQueryQjldRespVO> getDataQueryQjld(@RequestParam("id") Long id) {
        DataQueryQjldDO dataQueryQjld = dataQueryQjldService.getDataQueryQjld(id);
        return success(BeanUtils.toBean(dataQueryQjld, DataQueryQjldRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得数据查询-全景雷达分页")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjld:query')")
    public CommonResult<PageResult<DataQueryQjldRespVO>> getDataQueryQjldPage(@Valid DataQueryQjldPageReqVO pageReqVO) {
        PageResult<DataQueryQjldDO> pageResult = dataQueryQjldService.getDataQueryQjldPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DataQueryQjldRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出数据查询-全景雷达 Excel")
    //@PreAuthorize("@ss.hasPermission('business:data-query-qjld:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDataQueryQjldExcel(@Valid DataQueryQjldPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DataQueryQjldDO> list = dataQueryQjldService.getDataQueryQjldPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "数据查询-全景雷达.xls", "数据", DataQueryQjldRespVO.class,
                        BeanUtils.toBean(list, DataQueryQjldRespVO.class));
    }

}